#ifndef _TIMER_NODE_H_
#define _TIMER_NODE_H_

const int TIME_ZERO = 0;
const int MAX_TIME = 0x8FFFFFFF;


template< class TYPE >
class Timer_Node
{
public:
	Timer_Node(void);
	~Timer_Node(void);

	//singly linked list
	void set( const TYPE& type,
				const void* arg,
				unsigned long time_value,
				unsigned long interval,
				unsigned long timer_id,
				Timer_Node<TYPE>* next);

	//double linked list version
	void set ( const TYPE& type,
		const void* arg,
		unsigned long time_value,
		unsigned long interval,
		unsigned long timer_id,
		Timer_Node<TYPE>* prev,
		Timer_Node<TYPE>* next );

	// get the type
	TYPE& get_type(void);

	// set the type
	void set_type(TYPE& type);

	// get the arg
	const void* get_arg(void);

	//set the arg
	void set_arg(void* arg);

	//get the timer value
	unsigned long get_timer_value(void) const;

	//set the timer value
	void set_timer_value( unsigned long timer_value );

	//get the timer interval
	unsigned long get_interval(void) const;

	//set the timer interval
	void set_interval( unsigned long interval );

	//get the previous pointer
	Timer_Node<TYPE>* get_prev(void);

	//set the previous pointer
	void set_prev( Timer_Node<TYPE>* prev );

	//get the next pointer
	Timer_Node<TYPE>* get_next(void);

	//set the next pointer
	void set_next( Timer_Node<TYPE>* next );

	//get the timer_id.
	long get_timer_id (void) const;

	//set the timer_id.
	void set_timer_id (long timer_id);

	void on_timer_out( unsigned long );

	void on_timer_cancel();

private:
	// Type of object stored in the Queue
	TYPE type_;

	// Asynchronous completion token associated with the timer.
	const void *arg_;

	// Time until the timer expires.
	unsigned long timer_value_;

	// If this is a periodic timer this holds the time until the next
	// timeout.
	unsigned long interval_;

	// Pointer to previous timer.
	Timer_Node<TYPE> *prev_;

	// Pointer to next timer.
	Timer_Node<TYPE> *next_;

	// Id of this timer (used to cancel timers before they expire).
	long timer_id_;
};

#include "Timer_Node.cpp"
#endif//_TIMER_NODE_H_